package com.ciwong.epaper.modules.bookstore.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.bookstore.bean.GoodServicesBean;

import java.util.List;

/**
 *精品服务recyclerView的适配器
 * Created by Administrator on 2017/12/29.
 */

public class BestserviceAdapter extends RecyclerView.Adapter<BestserviceAdapter.MyViewHolder> implements View.OnClickListener{
	private Context context;
	private List<GoodServicesBean> goodServices;
	private View inflate;

	private OnItemClickListener mOnItemClickListener = null;

	public BestserviceAdapter(Context context, List<GoodServicesBean> goodServices, View inflate) {
		this.context = context;
		this.goodServices = goodServices;
		this.inflate = inflate;
	}

	@Override
	public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		MyViewHolder holder = new MyViewHolder(inflate);
		//将创建的View注册点击事件
		inflate.setOnClickListener(this);
		return holder;
	}

	@Override
	public void onBindViewHolder(MyViewHolder holder, int position) {
//		Glide.with(context).load(goodServices.get(position).getLogo()).into(holder.iv_service_face);
//		holder.tv_goodservice_title.setText(goodServices.get(position).getServiceName());
//		holder.tv_period.setText(goodServices.get(position).getPeriod());
//		holder.tv_buy_num.setText(goodServices.get(position).getBuyNum());
//		//将position保存在itemView的Tag中，以便点击时进行获取
//		holder.itemView.setTag(position);
	}

	@Override
	public int getItemCount() {
		return goodServices.size();
	}

	@Override
	public void onClick(View view) {
		if (mOnItemClickListener != null) {
			//使用getTag方法获取position
			mOnItemClickListener.onItemClick(view, (int) view.getTag());
		}
	}
	public void setOnItemClickListener(OnItemClickListener listener) {
		this.mOnItemClickListener = listener;
	}
	public interface OnItemClickListener {
		void onItemClick(View view, int position);
	}
	class MyViewHolder extends RecyclerView.ViewHolder {

		ImageView iv_service_face;
		TextView tv_goodservice_title;
		TextView tv_period;
		TextView tv_buy_num;

		public MyViewHolder(View view) {
			super(view);
			iv_service_face = (ImageView) view.findViewById(R.id.iv_service_face);
			tv_goodservice_title = (TextView) view.findViewById(R.id.goodservice_title);
			tv_period = (TextView) view.findViewById(R.id.tv_period);
			tv_buy_num = (TextView) view.findViewById(R.id.tv_buy_num);
		}
	}
}